package com.mg.yygh.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mg.yygh.common.result.Result;
import com.mg.yygh.model.user.UserInfo;
import com.mg.yygh.user.service.UserInfoService;
import com.mg.yygh.vo.user.UserInfoQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author M_Dragon
 * @date 2022/9/20/020 14:00
 */
@Api(tags = "平台管理用户")
@RestController
@RequestMapping("admin/user")
public class UserController {

    @Autowired
    private UserInfoService userInfoService;


    @ApiOperation("用户列表")
    @GetMapping("{page}/{limit}")
    public Result list(@PathVariable("page") Long page,
                       @PathVariable("limit") Long limit,
                       UserInfoQueryVo userInfoQueryVo){
        Page<UserInfo> pageParam = new Page<>(page, limit);
        IPage<UserInfo> pageModel = userInfoService.selectPage(pageParam,userInfoQueryVo);
        return Result.ok(pageModel);
    }

    @ApiOperation("用户状态锁定&解锁")
    @GetMapping("lock/{userId}/{status}")
    public Result lock(@PathVariable("userId") Long userId,
                       @PathVariable("status") Integer status){
        userInfoService.lock(userId,status);
        return Result.ok();
    }

    @ApiOperation("用户详情&就诊人信息")
    @GetMapping("show/{userId}")
    public Result show(@PathVariable("userId") Long userId){
        Map<String,Object> map = userInfoService.show(userId);
        return Result.ok(map);
    }

    @ApiOperation("实名认证审批")
    @GetMapping("approval/{userId}/{authStatus}")
    public Result approval(@PathVariable("userId") Long userId,
                           @PathVariable("authStatus") Integer authStatus){
        userInfoService.approval(userId,authStatus);
        return Result.ok();
    }
}
